<!--
 * @Author: your name
 * @Date: 2021-09-22 15:31:05
 * @LastEditTime: 2021-09-28 15:10:14
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \SuperMalld:\Projects\视频号h5商城\h5\src\App.vue
-->
<script>
export default {
  onLaunch: function() {
    // const updateManager = uni.getUpdateManager()
    // uni.getUpdateManager().onUpdateReady(function() {
    //   uni.showModal({
    //     title: '更新提示',
    //     content: '新版本已经准备好，是否重启应用？',
    //     success: function(res) {
    //       if (res.confirm) {
    //         // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
    //         updateManager.applyUpdate()
    //       }
    //     },
    //   })
    // })

    this.$api('AuthLoginByJsapi', { url: location.href }, 'POST')
      .then((res) => {
        let wx = window.wxSDK

        wx.config({
          // debug: true,
          appId: res.data.appId,
          timestamp: res.data.timestamp,
          nonceStr: res.data.nonceStr,
          signature: res.data.signature,
          jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData', 'chooseWXPay'],
        })

        // wx.ready(() => {
        //   let topic = uni.getStorageSync('topic')
        //   let ids = topic.id || 41
        //   let title = topic.subtitle || '泽超新福礼'
        //   let desc = topic.content || '快来参与吧！'
        //   let img = topic.picUrl || window.location.origin + 'logo.jpg'
        //   let link = window.location.origin + '?myId=' + ids

        //   wx.updateAppMessageShareData({
        //     title: title,
        //     desc: desc,
        //     link: link,
        //     imgUrl: img,
        //     success: () => {},
        //   })
        //   wx.updateTimelineShareData({
        //     title: title,
        //     link: link,
        //     imgUrl: img,
        //     success: () => {},
        //   })
        // })

        // wx.error((response) => {
        //   console.log(response)
        // })
      })
      .catch((err) => {
        console.log('JSSDK鉴权', err)
      })
  },
  onShow: function(options) {
    let token = uni.getStorageSync('token')
    if (token) {
      this.globalData.hasLogin = true
    } else {
      this.globalData.hasLogin = false
    }
    // user
    //   .checkLogin()
    //   .then((res) => {
    //     this.globalData.hasLogin = true
    //   })
    //   .catch(() => {
    //     this.globalData.hasLogin = false
    //   })
  },
  globalData: {
    hasLogin: false,
  },
}
</script>
